const express = require('express')
const createError = require('http-errors')

var router = express.Router()

// 暂定一个过滤器
router.use((req, res, next) => {
  console.log('filter is working!')
  next()
})

router.get('/', (req, res, next) => {
  res.send('ok')
})

// 404处理
router.use((req, res, next) => {
  next(createError(404))
  //res.send('Sorry this path is not found, 404 process is working!')
})

// 错误处理
router.use(function(err, req, res, next) {
  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = router